class CurrentSessionHydraulicLine:
    hydraulic_line = {}
    total_pressure_drop = None
    total_resistance_coefficient = None

    def add_element(self, obj):
        self.hydraulic_line.setdefault(obj.index, obj)

    def edit_element(self, obj):
        self.hydraulic_line[obj.index] = obj

    def update_total_pressure_drop(self, unit: str = 'Па'):
        self.total_pressure_drop = sum((elem.pressure_drop() for elem in self.hydraulic_line.values()))
        if unit == 'Па':
            return round(self.total_pressure_drop, 1)
        elif unit == 'МПа':
            return round(self.total_pressure_drop / 10**6, 2)
        elif unit == 'ат':
            return round(self.total_pressure_drop / 98066.5, 2)



    def update_total_resistance_coefficient(self):
        self.total_resistance_coefficient = sum(
            (elem.total_resistance_coefficient() for elem in self.hydraulic_line.values()))
        return round(self.total_resistance_coefficient, 3)


